package com.atguigu.juc.chap08;

import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class ScheduledAtFixRateDemo {

    public static void main(String[] args) {

        ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(3);
        System.out.println("当前时间 " + new Date());

        // 延迟执行
        scheduledThreadPool.scheduleAtFixedRate(() -> {
            System.out.println(Thread.currentThread().getName() + " 定时任务被执行" + new Date());
        }, 5, 1, TimeUnit.SECONDS);

        // 不要关闭这个对象，因为任务会一直执行
        // scheduledThreadPool.shutdown();
    }
}